package com.bd.rj.frontstage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bd.rj.common.entity.Interview;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 白世俊
 * @since 2025-01-03
 */
@Mapper
public interface InterviewMapper extends BaseMapper<Interview> {
    /**
     * 根据用户id和状态查询面试记录
     * @param uid
     * @param status
     * @return
     */
    @Select({
            "<script>",
            "SELECT interview.*,post.postname,enterprise.ename ",
            "FROM interview ",
            "JOIN post ON interview.pid = post.id ",
            "JOIN enterprise ON post.eid = enterprise.id ",
            "WHERE interview.uid = #{uid} ",
            "<if test='status!= null'>",
            "AND interview.status = #{status}",
            "</if>",
            "</script>"
    })
    List<Map<String, Object>> getviewById(@Param("uid") Long uid, @Param("status") Integer status);

    /**
     * 根据用户id查询企业名称
     * @param uid
     * @return
     */
    @Select("SELECT  enterprise.ename \n" +
            "FROM interview \n" +
            "JOIN post ON interview.pid = post.id \n" +
            "JOIN enterprise ON post.eid = enterprise.id \n" +
            "WHERE interview.uid = #{uid}")
    List<Map<String, Object> > getEnameByUid(@Param("uid") Long uid);

    /**
     * 根据企业名称查询面试记录
     * @param ename
     * @return
     */
    @Select("SELECT interview.*, post.postname, enterprise.ename \n" +
            "FROM interview \n" +
            "JOIN post ON interview.pid = post.id \n" +
            "JOIN enterprise ON post.eid = enterprise.id \n" +
            "WHERE enterprise.ename = #{ename}")
    List<Map<String, Object>> getviewByEname(@Param("ename") String ename);
}
